import { OrderEntity } from "@/interfaces/OrderEntity"
import moment from "moment"


const OrderCard = ({
    order,
    onFinish
}: {
    order: OrderEntity,
    onFinish: (order: OrderEntity) => void
}) => {
    return (
        <div key={order.id} className="card w-96 bg-base-100 shadow-xl bordered">
            <div className="card-body">
                <h2 className="card-title">
                    {moment(order.createAt).format("YYYY-MM-DD")}
                    <div className="badge badge-secondary">{order.status}</div>
                </h2>
                <p>{order.shop.name}</p>
                <div className="h-16 overflow-y-auto hidden">
                    {order.OrderOnGoods?.map((line) => (
                        <div className="flex justify-between" key={line.goodsId + "_" + line.orderId}>
                            <div>
                                {line.goods?.name}
                            </div>
                            <div>
                                {line.count}
                            </div>
                        </div>
                    ))}
                </div>
                <div className="flex justify-between">
                    <div>
                        配送费￥{order.shop.total / 100}
                    </div>
                    <div>
                        总数量{order.OrderOnGoods?.reduce((count, item) => count + item.count, 0)}
                    </div>
                    <div>
                        总金额￥{((order.OrderOnGoods?.reduce((count, item) => count + item.count * (item.goods?.price || 0), 0) || 0) + order.shop.total) / 100}
                    </div>
                </div>
                <div className="card-actions justify-end h-10">
                    {order.status === "待配送" && (
                        <button onClick={onFinish.bind(null, order)} className="btn btn-primary">配送</button>
                    )}
                </div>
            </div>
        </div>
    )
}
export default OrderCard